package juc.lock.print;

/**
 * @program: check-repetition
 * @description:
 * @author: hjk
 * @create: 2021-07-12 17:01
 **/
/**
 * volatile 关键字实现线程交替加减
 */
public class TestVolatile {
    /**
     * 交替加减
     * @param args
     */
    public static void main(String[] args){
        DemoClazz demoClass = new DemoClazz();
        new Thread(() ->{
            for (int i = 1; i <= 10; i++) {
                demoClass.printA(i);
            }
        }, "A 线程").start();
        new Thread(() ->{
            for (int i = 1; i <= 10; i++) {
                demoClass.printB(i);
            }
        }, "B 线程").start();
        new Thread(() ->{
            for (int i = 1; i <= 10; i++) {
                demoClass.printC(i);
            }
        }, "C 线程").start();
    }
}
